<?php

namespace app\admin\model\outhouse;

use app\admin\model\information\Shelves;
use app\admin\model\information\Warehouse;
use think\Db;
use think\Model;
use traits\model\SoftDelete;

class RdoutrecordList extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'rdoutrecord_list';
    
    // 自动写入时间戳字段
   // protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function rdoutrecord()
    {
        return $this->hasOne('\app\admin\model\outhouse\rdoutrecord', 'code', 'code');
    }

    public function shelves(){
        return $this->hasOne('\app\common\model\Shelves','id','shelves_id')->field('id,name');
    }

    /**
     * @param $params
     * @param $code  单号
     * @param $createtime
     * @return void
     */
    public static function addDataByBatch($params, $code, $createtime)
    {
        foreach ($params['cInvCode'] as $k => $v) {
            $list[] = [
                'code' => $code,
                'shelves_id' => $params['shelves_id'][$k],
                'cInvCode' => $v,
                'iQuantity' => $params['numbers'][$k],
                'createtime' => $createtime,
            ];
        }
        //表体
        Db::name('rdoutrecord_list')->insertAll($list);
    }






}
